from typing import List
from leetcode_test import ListNode
from queue import PriorityQueue

class Solution(object):
    def mergeKLists(self, lists):
        """
        :type lists: List[ListNode]
        :rtype: ListNode
        """
        head = point = ListNode(0)
        q = PriorityQueue()
        for l in lists:
            if l:
                q.put((l.val, l))
        while not q.empty():
            val, node = q.get()
            point.next = ListNode(val)
            point = point.next
            node = node.next
            if node:
                q.put((node.val, node))
        return head.next

if __name__ == "__main__":
    l = [
        ListNode.create([1,4,5]),
        ListNode.create([1,3,4]),
        ListNode.create([2,6])
    ]
    print(l[0].val, l[0].next.val)
    print(Solution().mergeKLists(l))